import { prop, Ref, arrayProp } from "@typegoose/typegoose";
import { IsUrl, IsNotEmpty } from "class-validator";
import { Commodity } from "./commodity.model";
import { ApiModelProperty } from "@nestjs/swagger";

class Appraise {
  @prop()
  meet!: Number
  @prop()
  rational!: Number
  @prop()
  quality!: Number
}

export class Selle {
  @ApiModelProperty({ description: '店铺名称', example: '黑凤梨小蛋糕' })
  @prop()
  @IsNotEmpty({ message: '店铺名称不能为空' })
  name!: String

  @ApiModelProperty({ description: '店铺图标', example: 'https://shubuzuo.top/img/logo.jpg', required: false })
  @prop()
  @IsUrl()
  logo?: String

  @ApiModelProperty({ description: '店铺商品', example: ['Commodity._id'], type: [String], required: false })
  @arrayProp({ itemsRef: Commodity })
  commodities?: Ref<Commodity> []

  @ApiModelProperty({ description: '总交易量', example: 124, type: Number, required: true })
  @prop({ default: 0 })
  salesVolume?: Number

  @ApiModelProperty({ description: '商品总量', example: 123, type: Number, required: true })
  @prop({ default: 0 })
  commoditiesCount: Number

  @ApiModelProperty({ description: '店铺评价', example: {
    meet : 0,
    rational: 0,
    quality: 0
  }, type: Appraise, required: false })
  @prop()
  appraise?: Appraise

  @ApiModelProperty({ description: '收藏量', example: 15 })
  @prop({ default : 0 })
  collectCount!: Number
}
